/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package panaderialabaguette;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author oscar
 */
public class FormatoTabla extends DefaultTableCellRenderer{

    int stock = 5 ; //indica la columna que contiene el stock de un producto
    final int stockMin = 5 ;  // stock mínimo permitido
    int stockNulo = 0;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        this.setOpaque(true);
        this.setBackground(Color.white);


        if (isSelected)
        {
            this.setOpaque(true);
            this.setBackground(table.getSelectionBackground());
        }

        if (column == stock)
        {
            int celda_stock = Integer.parseInt(table.getValueAt(row, column).toString());
            if (celda_stock > stockNulo && celda_stock < stockMin)
            {
                this.setOpaque(true);
                this.setBackground(Color.yellow);
            }

            if (celda_stock == stockNulo)
            {
                this.setOpaque(true);
                this.setBackground(new Color(230,40,40));
                //this.setBackground(Color.RED); use el de arriba porque el rojo posta era muy chillon
            }
        }
        return this;
        }



    }



